package com.hq.ims.userpc.controller;

import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.service.BaseUserTodoStatisticsService;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.utils.WebExpandUtils;
import com.hq.ims.data.vo.UserTodoStatisticsMapstruct;
import com.hq.utils.vo.ReturnVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "待办")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_USER_PC_URL_PREFIX + "/todo")
public class UserTodoController {

    @Resource
    private BaseUserTodoStatisticsService baseUserTodoStatisticsService;

    @ApiOperation(value = "清除待办", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/clearTodo", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> clearTodo(
            @RequestBody UserTodoStatisticsMapstruct.ClearTodo clearTodo
    ) {
        String companyId = WebExpandUtils.getHeadCompanyId();
        clearTodo.setCompanyId(companyId);
        switch (clearTodo.getUserTodoType()) {
            case BusinfoAuditNotifyCount:
            case BusinfoFeedbackNotifyCount:
            case BusinfoReceiveNotifyCount:
            case BusinfoForewarningNotifyCount:
            case UserJoinCompanyNotifyCount:
            case CompanyAuditNotifyCount:
                clearTodo.setUserId(AppUtils.getUserId());
                break;
            default:
                break;
        }
        baseUserTodoStatisticsService.clearTodo(clearTodo);
        return ReturnVo.buildSuccess(true);
    }

    @ApiOperation(value = "获取待办数量", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getMyTodo", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<UserTodoStatisticsMapstruct.UserTodoStatisticsVo>> getMyTodo(

    ) {
        String companyId = WebExpandUtils.getHeadCompanyId();
        String userId = AppUtils.getUserId();
        List<UserTodoStatisticsMapstruct.UserTodoStatisticsVo> voList = baseUserTodoStatisticsService.getByCompanyIdAndUserId(companyId, userId);
        return ReturnVo.buildSuccess(voList);
    }

}
